<?php 
header("content-type: text/html; charset=utf-8");

class _Object
{
    private static $mixins = array();

    public static function implement($target)
    {
        $class = get_called_class();

        if (!isset(self::$mixins[$class]))
        {
            self::$mixins[$class] = array();
        }

        foreach (get_class_methods($target) as $method)
        {
            self::$mixins[$class][$method] = $target;
        }
    }

    public function class_name()
    {
        return self::get_class($this);
    }

    public function __call($method, $params)
    {
        $params = array_merge(array($this), $params);
        $class  = $class = get_called_class();
        
        $mixin = $this->find_mixin($class, $method);

		call_user_func_array($mixin, $params);
    }

    private function find_mixin($class, $method)
    {
    	while ($class != NULL) 
    	{
	        if (isset(self::$mixins[$class][$method]))
	        {
	            $target = self::$mixins[$class][$method];

	            return array($target, $method);
	        }

	        $class = get_parent_class($class);
    	}

        throw new MethodException("方法 $method 不存在");
    }
}

class Playable
{
	public function play($that)
	{
		echo "一起玩吧，".$that->name;
	}
}

class Base extends _Object 
{
	public $name = "段光伟<br/>";
}

class Child extends Base {}

Base::implement(new Playable());

$base = new Base();
$child = new Child();

$base->play();
$child->play();

?>